﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace WebApiVersionControl.Helper
{
    public class LogHelper
    {
        /// <summary>
        /// 写入日志
        /// </summary>
        /// <param name="logPath">日志存放的位置</param>
        /// <param name="logMessage">日志内容</param>
        public void WriteLog(string logPath, string logMessage)
        {
            StreamWriter sw;
            if (!Directory.Exists(logPath))
            {
                Directory.CreateDirectory(logPath);
            }
            logPath = logPath + DateTime.Now.ToString("yyyyMMdd") + ".Log";
            if (File.Exists(logPath))
            {
                sw = File.AppendText(logPath);
            }
            else
            {
                sw = File.CreateText(logPath);
            }
            sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "\t" + logMessage);
            sw.Close();
        }
    }
}